import 'package:flutter/material.dart';
import 'package:get/get.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
        theme: ThemeData(
          useMaterial3: false,
          primarySwatch: Colors.blue,
        ),
        home: Scaffold(
          appBar: AppBar(
            title: const Text("Flutter APP"),
          ),
          body: const MyHome(),
        )
    );
  }
}

class MyHome extends StatelessWidget {
  const MyHome({super.key});

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          ElevatedButton(onPressed: (){
            Get.defaultDialog(
              title: "提示信息!",
              middleText: "您确定要删除吗?",
              confirm: ElevatedButton(onPressed: (){
                print("确定");
                //可以通过路由返回
                Navigator.pop(context);
              }, child: const Text("确定")),
              cancel: ElevatedButton(onPressed: (){
                print("取消");
                //GetX封装了返回方法
                Get.back();
              }, child: const Text("取消")),
            );
          }, child: const Text("GetX Dialog")),
          ElevatedButton(onPressed: (){ 
            Get.snackbar("提示!", "您还没有登录!",
                //设置弹出位置
                snackPosition:SnackPosition.BOTTOM
            );
          }, child: const Text("GetX snackbar")),

          ElevatedButton(onPressed: (){
              Get.bottomSheet(
                Container(
                  //Get.isDarkMode判断是否为夜间模式
                  color: Get.isDarkMode ?  Colors.black : Colors.white,
                  height: 150,
                  child: Column(
                    children: [
                      ListTile(
                        title: Text("白天模式",style: TextStyle(color: Get.isDarkMode ? Colors.white :Colors.black),),
                        leading: Icon(Icons.wb_sunny_outlined,color: Get.isDarkMode ? Colors.white :Colors.black,),
                        onTap: () {
                          //GetX 改变主题
                          Get.changeTheme(ThemeData.light(useMaterial3: false));
                          Get.back();
                        },
                      ),
                      ListTile(
                        title: Text("夜间模式",style: TextStyle(color: Get.isDarkMode ? Colors.white :Colors.black),),
                        leading: Icon(Icons.wb_sunny,color: Get.isDarkMode ? Colors.white :Colors.black,),
                        onTap: () {
                          Get.changeTheme(ThemeData.dark(useMaterial3: false));
                          Get.back();
                        },
                      ),
                    ],
                  ),
                )
              );
          }, child: const Text("GetX 切换主题")),
        ],
      ),
    );
  }
}


